#pragma once
#ifndef BORROWRECORD_H
#define BORROWRECORD_H

#include <string>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
using namespace std;

class BorrowRecord {
private:
    int recordId;       // 记录号
    string bookId;      // 图书号
    string readerId;    // 读者号
    time_t borrowDate;  // 借阅日期
    time_t dueDate;     // 应还日期
    time_t returnDate;  // 实际归还日期
    bool isReturned;    // 是否归还
    double fineAmount;  // 罚款金额

public:
    // 构造函数
    BorrowRecord();
    BorrowRecord(int id, string bId, string rId, time_t borrow, time_t due);

    // Getter方法
    int getRecordId() const { return recordId; }
    string getBookId() const { return bookId; }
    string getReaderId() const { return readerId; }
    time_t getBorrowDate() const { return borrowDate; }
    time_t getDueDate() const { return dueDate; }
    time_t getReturnDate() const { return returnDate; }
    bool getIsReturned() const { return isReturned; }
    double getFineAmount() const { return fineAmount; }

    // Setter方法
    void setReturnDate(time_t date) { returnDate = date; }
    void setIsReturned(bool returned) { isReturned = returned; }
    void setFineAmount(double amount) { fineAmount = amount; }

    // 功能方法
    void displayInfo() const;
    string toString() const;
    static BorrowRecord fromString(const string& data);
    double calculateFine() const;
    int getOverdueDays() const;

    // 静态方法
    static string timeToString(time_t time);

    // 操作符重载
    bool operator==(const BorrowRecord& other) const {
        return recordId == other.recordId;
    }
};

#endif